import {serverUrl,appids} from './common/js/config'
App({
  onShow(){
    this.getListNames()
    this.getRequest('/applet/site/detail', 'GET', '').then(res => {
      if (res.code == 200) {
        res.data.siteInfo.coverUrl = this.globalData.serverUrl+res.data.siteInfo.coverUrl
        res.data.siteInfo.logoUrl = this.globalData.serverUrl+res.data.siteInfo.logoUrl
        res.data.siteInfo.wechatQrUrl = this.globalData.serverUrl+res.data.siteInfo.wechatQrUrl
        this.globalData.siteInfo = res.data.siteInfo
      }
    })
  },
  onLaunch: function () {
   
  },
  isValidPhoneNumber(phoneNumber) {
        var pattern = /^1[3456789]\d{9}$/;
        return pattern.test(phoneNumber);
      },
   getCurrentPageUrl(e){
    var pages = getCurrentPages(e) //获取加载的页面
    var currentPage = pages[pages.length-1] //获取当前页面的对象
    // console.log(currentPage.options);
    // let str =''
    // if(currentPage.options.type && currentPage.options.id){
    //   str = '?type='+currentPage.options.type+'&id='+currentPage.options.id
    // }else if(currentPage.options.type && !currentPage.options.id){
    //   str = '?type='+currentPage.options.type
    // }else{
    //   str = ''
    // }
    // var url = currentPage.route+str //当前页面url
    // return url
    return currentPage.options.typenew
    },
    getRequest(url,method,data){
      return new Promise(function(resolve, reject){
        if(method=='POST'){
          tt.request({
            url:serverUrl+url,
            method,
            header:{appid:appids},
            data,
            success: (res) => {
              let resp = res.data
              resolve(resp)
            },
            fail: (res) => {
              
            },
          });
        }else{
          tt.request({
            url:serverUrl+url+'/'+data,
            header:{appid:appids},
            method,
            success: (res) => {
              let resp = res.data
              resolve(resp)
            },
            fail: (res) => {
              
            },
          });
        }
        
    });
      
    },
    getListNames(){
      this.getRequest('/applet/nav/list', 'GET', '').then(res => {
        if (res.code == 200) {
          this.globalData.listName = res.data.bannerList.filter(item=>{
            return (item.isView==1 && item.type != 4 && item.type != 5)
          })
        }
      })
    },
  globalData:{
    serverUrl:serverUrl,
    siteInfo:{},
    listName:[],
  }
})
